#define _CRT_SECURE_NO_WARNINGS 1
#include "RBTree.h"
#include <iostream>
#include <initializer_list>
using namespace std;
namespace lnb
{
	template<class K, class V>
	class map
	{
		struct Key0fValue;
		typedef RBTree<K, pair<const K, V>, Key0fValue> tree;
	public:
		typedef typename tree::iterator iterator;
		typedef typename tree::const_iterator const_iterator;
		struct Key0fValue
		{
			K operator()(const pair<const K, V>& kv)
			{
				return kv.first;
			}
		};

		map(const initializer_list<pair<K,V>>& in)
		{
			for (auto& e : in)
			{
				insert(e);
			}

		}

		iterator begin()
		{
			return _rbtree.begin();
		}

		iterator end()
		{
			return _rbtree.end();
		}

		const_iterator begin()const
		{
			return _rbtree.begin();
		}

		const_iterator end()const
		{
			return _rbtree.end();
		}

		/*bool insert(const pair<K, V>& kv)
		{
			return _rbtree.Insert(kv);
		}*/

		pair<iterator,bool> insert(const pair<K, V>& kv)
		{
			return _rbtree.Insert(kv);
		}

		V& operator[](const K& key)
		{
			return (*(insert(make_pair(key, V())).first)).second;
		}


	private:

		tree _rbtree;
	};
}
void test()
{
	 lnb::map<int, int> m{{1,2},{2,3}};
	m.insert(make_pair(1, 1));
	m.insert(make_pair(2, 1));
	m.insert(make_pair(0, 1));
	m.insert(make_pair(4, 1));
	m.insert(make_pair(-1, 1));
	lnb::map<int, int>::iterator it = m.begin();
	while (it != m.end())
	{
		cout << (*it).first << " "<<it->second<<endl;
		++it;
	}
	m[-1] = 100;
	lnb::map<int, int>::iterator sit = m.begin();
	cout << (sit)->second << endl;
	initializer_list<int> li;


}